<template>
  <div>
      <f-table ref="table" size="small" rowKey="orderId" :showSetting="true" setting-key='lp_ordertask3'  :tableColumns="columns"  order="sendDate" :multiple="false" :scroll="scroll" :operator="operator" :params="queryParam" :api="api.busOrder" handler="nqOrderListHandler">
        <span slot="orderNo" slot-scope="text, record, index">
            <span v-clipboard:copy="text" v-clipboard:success="onCopy" style="cursor:pointer">{{text}}</span>
        </span>
        <span slot="supplierBondType" slot-scope="text, record, index">
            <a-tag color="#2db7f5" v-if="text==0">不垫付</a-tag>
            <a-tag color="purple" v-if="text==1">底价</a-tag>
            <a-tag color="purple" v-if="text==2">底价+税金</a-tag>
            <a-tag color="purple" v-if="text==3">税金</a-tag>
            <a-tag color="purple" v-if="text==6">底价/2+税金</a-tag>
            <a-tag color="purple" v-if="text==5">全额垫付</a-tag>
            <a-tag color="purple" v-if="text==8">销售金额*费率</a-tag>
        </span>
        <span slot="customBondType" slot-scope="text, record, index">
           <a-tag color="#2db7f5" v-if="text==0">全款</a-tag>
            <a-tag color="purple" v-if="text==1">底价</a-tag>
            <a-tag color="purple" v-if="text==2">底价+税金</a-tag>
            <a-tag color="purple" v-if="text==6">底价/2+税金</a-tag>
            <a-tag color="purple" v-if="text==3">税金</a-tag>
            <a-tag color="purple" v-if="text==5">全额资信</a-tag>
            <a-tag color="purple" v-if="text==7">预收款</a-tag>
        </span>
        <span slot="sendState" slot-scope="text, record, index">
            <a-tag color="#87d068" v-if="text==0">未发货</a-tag>
            <a-tag color="#108ee9" v-if="text==1">已发货</a-tag>
        </span>
        <span slot="orderState" slot-scope="text, record, index">
            <a-tag color="pink" v-if="text==0">未提交</a-tag>
            <a-tag color="#87d068" v-if="text==1" @click="processImg(record)">{{record.taskName}}</a-tag>
            <a-tag color="#f50" v-if="text==2">已审批</a-tag>
        </span>
        <span slot="action" slot-scope="text, record">
          <template>
            <a @click="$refs.orderInfoDrawer.showDrawer(record)">查看</a>
            <a-divider type="vertical" />
          </template>
          <a-dropdown>
            <a class="ant-dropdown-link">更多 <a-icon type="down"/></a>
            <a-menu slot="overlay">
                <a-menu-item v-if="record.processInstanceId!=''&&record.processInstanceId!=null">
                <a href="javascript:;" @click="processImg(record)">审批进度</a>
              </a-menu-item>
              <a-menu-item>
                <a href="javascript:;" @click="printOrder(record)">发货单</a>
              </a-menu-item>
            </a-menu>
          </a-dropdown>
        </span>
      </f-table>
      <order-info-drawer ref="orderInfoDrawer"></order-info-drawer>
      <process-image ref="processImg" v-if="processImageVisible" :visible.sync="processImageVisible" :processInstanceId="processInstanceId"></process-image>
      <print-modal ref="printModal"></print-modal>
  </div>
</template>
<script>

  import api from './../js/api'
  import OrderInfoDrawer from './../order_info_drawer'
  import ProcessImage from '../../../flowable/process/process_image'
  import PrintModal from './../print/print_modal'

  export default {
    name: 'OrderEnd',
    components: {
      PrintModal,
      ProcessImage,
      OrderInfoDrawer
    },
    data() {
      let me = this
      //操作按钮
      let operator = []
      return {
        api: Object.assign(api, this.api),
        //列表初始化查询参数
        queryParam: {
          activeKey: 2
        },
        activeKey:0,
        processImageVisible: false,
        scroll: { x: true },
        // 表头
        columns: [
          {
            title: '#',
            width: '50px',
            fixed: 'left',
            align: 'center',
            customRender: (text, record, index) => index + 1
          },
          {
            title: '单号',
            align: 'left',
            width: '135px',
            dataIndex: 'orderNo',
            fixed: 'left',
            scopedSlots: { customRender: 'orderNo' }
          },
          {
            title: '发货日期',
            align: 'left',
            sorter: true,
            width: '135px',
            dataIndex: 'sendDate',
            customRender: function(text, record, index) {
              if (text) {
                return text
              } else {
                return '未发货'
              }
            }
          },
          /*    {
                title: '订单类型',
                align: 'center',
                dataIndex: 'billsType'
              },*/
          {
            title: '供货方',
            align: 'left',
            width: '140px',
            sorter: true,
            ellipsis: true,
            dataIndex: 'supplierName'
          },
          {
            title: '供方资信',
            align: 'left',
            width: '100px',
            sorter: true,
            dataIndex: 'supplierBondType',
            scopedSlots: { customRender: 'supplierBondType' }
          },
          {
            title: '购货方',
            align: 'left',
            ellipsis: true,
            width: '140px',
            sorter: true,
            dataIndex: 'customName'
          },
          {
            title: '购方资信',
            align: 'center',
            width: '100px',
            sorter: true,
            dataIndex: 'customBondType',
            scopedSlots: { customRender: 'customBondType' }
          },
          {
            title: '部门',
            align: 'left',
            sorter: true,
            width: '100px',
            dataIndex: 'deptName'
          },
          {
            title: '业务员',
            align: 'left',
            width: '100px',
            dataIndex: 'saleManName'
          },
          {
            title: '发货金额',
            align: 'left',
            width: '100px',
            dataIndex: 'saleAmount'
          },
          {
            title: '收款金额',
            align: 'left',
            width: '100px',
            dataIndex: 'takeAmount'
          },
          {
            title: '收款日期',
            align: 'left',
            width: '125px',
            sorter: true,
            dataIndex: 'takeDate'
          },
          {
            title: '收款账户',
            align: 'left',
            ellipsis: true,
            width: '125px',
            dataIndex: 'bankName',
            customRender: function(text, record, index) {
              if (record.customBondType == 0) {
                return '客户付'
              } else {
                return text
              }
            }
          },
          {
            title: '制单人',
            align: 'left',
            width: '85px',
            dataIndex: 'nickName'
          },
          {
            title: '创建日期',
            align: 'left',
            width: '155px',
            sorter: true,
            dataIndex: 'createTime'
          },
          {
            title: '订单状态',
            align: 'center',
            fixed: 'right',
            width: '85px',
            dataIndex: 'orderState',
            scopedSlots: { customRender: 'orderState' }
          },
          {
            title: '操作',
            align: 'center',
            width: 'auto',
            fixed: 'right',
            dataIndex: 'action',
            scopedSlots: { customRender: 'action' }
          }
        ],
        operator: operator
      }
    },
    created() {
    },
    mounted() {

    },

    methods: {
      onCopy() {
        this.$message.success('复制成功!')
      },
      onLoad() {
        this.$refs.table.refresh()
      },
      processImg(order) {
        this.processInstanceId = order.processInstanceId
        this.processImageVisible = true
      },
      printOrder(record) {
        this.$refs['printModal'].open(record.orderId, 1)
      },
      changeHandler(activeKey,searchParams){
        this.activeKey=activeKey;
        let params={};
        if(searchParams instanceof Object){
          params=Object.assign({},{activeKey:this.activeKey},searchParams);
        }else{
          params={activeKey:this.activeKey};
        }
        this.$refs.table.refresh(true,params)
      }
    }
  }
</script>
